package cn.jlonely.xyhx.utils;

import java.security.MessageDigest;

public class SHA256Util {
    public static String sha256(String data) throws Exception {
        MessageDigest md = MessageDigest.getInstance("SHA-256");
        byte[] digest = md.digest(data.getBytes());
        StringBuilder sb = new StringBuilder();
        for (byte b : digest) {
            sb.append(String.format("%02x", b));
        }
        return sb.toString();
    }

    public static void main(String[] args) throws Exception {
        String data = "Hello, Spring Boot!";
        System.out.println("SHA-256: " + sha256(data));
    }
}
